-
Notifications
You must be signed in to change notification settings - Fork 15
feat(toolbox-langchain): Support per-invocation auth via RunnableConfig
#291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: anubhav-state-li
Are you sure you want to change the base?
Conversation
d33d044
to
6d9a532
Compare
931c9fc
to
93fd46d
Compare
6d9a532
to
eadd7d0
Compare
93fd46d
to
336b8d5
Compare
/gcbrun |
eadd7d0
to
a304b28
Compare
336b8d5
to
0f50eb0
Compare
RunnableConfig
packages/toolbox-langchain/src/toolbox_langchain/async_tools.py
Outdated
Show resolved
Hide resolved
In this case, we expect users to use dynamic methods for fetching tokens like getGoogleIdToken. |
a304b28
to
0418ed6
Compare
e1fd6d1
to
22aa329
Compare
Not necessarily in such a function like this one. For instance the app dev could fetch the user ID token from the frontend through a login button, and the app ID could be injected as an env var. Does that make sense? |
0418ed6
to
0a69d9f
Compare
09410c4
to
f41566a
Compare
Summary
This PR introduces a major enhancement to the
toolbox-langchain
package by adding support for dynamic, per-invocation authentication. This is achieved by readingauth_token_getters
from LangChain's standardRunnableConfig
, enablingToolboxTool
to be used safely and effectively in multi-user environments like LangGraph.Motivation
Currently, authentication tokens can only be provided to a
ToolboxTool
at initialization time, either viaToolboxClient.load_tool/load_toolset
or by callingtool.add_auth_token_getters()
on the tool instance. This static binding of credentials poses a significant challenge in modern agentic frameworks like LangGraph.Challenge
In LangGraph, a single graph containing tool instances is often created once and then shared across multiple users and requests. It is insecure and impractical to configure these shared tool instances with any single user's credentials. The required credentials must be provided dynamically, on a per-request basis.
Proposed Solution
This PR solves this problem by introducing a third, invocation-time method for providing auth. It leverages LangChain's idiomatic
RunnableConfig
as the vehicle for passing request-specific authentication, makingtoolbox-langchain
fully compatible with multi-tenant and shared-use patterns.Description of Changes
The core of this change lies in how the
ToolboxTool
handles an invocation:_arun
/_run
) is updated to accept theconfig: RunnableConfig
argument, which is standard in the LangChain.config["configurable"]["auth_token_getters"]
.auth_token_getters
are found in the config, the tool:a. Introspects its own authentication and authorization requirements (using the properties exposed in fix(toolbox-core): Expose authorization token requirements on
ToolboxTool
#294).b. Creates a temporary, in-memory copy of the underlying proxied
ToolboxTool
. This is critical, as it ensures the original shared tool instance is never mutated.auth_token_getters
from theconfig
are applied to this new, temporary copy of the tool using itsadd_auth_token_getters
method.This mechanism provides a thread-safe and secure way to handle user-specific credentials without affecting the shared state of the primary tool in the graph.
Usage Example